package com.yuanfengPlus.goodsManage.goodsManage.service.Impl;

import com.yuanfengPlus.goodsManage.goodsManage.dao.GoodsInfoDao;
import com.yuanfengPlus.goodsManage.goodsManage.model.GoodsInfo;
import com.yuanfengPlus.goodsManage.goodsManage.service.GoodsInfoService;
import com.yuanfengPlus.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsInfoServiceImpl implements GoodsInfoService {

    @Autowired
    private GoodsInfoDao goodsInfoDao;

    @Override
    public Result addGoodsInfo(GoodsInfo goodsInfo) {
        int rows = goodsInfoDao.addGoodsInfo(goodsInfo);
        return rows > 0 ? Result.success("添加成功") : Result.failure(400,"添加失败");
    }

    @Override
    public Result updateGoodsInfo(GoodsInfo goodsInfo) {
        int rows = goodsInfoDao.updateGoodsInfo(goodsInfo);
        return rows > 0 ? Result.success("更新成功") :  Result.failure(400,"添加失败");
    }

    @Override
    public Result updateGoodsBrandStatus(Integer id, String status) {
        int rows = goodsInfoDao.updateGoodsBrandStatus(id, status);
        return rows > 0 ? Result.success("状态更新成功") :  Result.failure(400,"更新失败");
    }

    @Override
    public Result queryGoodsInfo() {
        List<GoodsInfo> goodsInfos = goodsInfoDao.queryGoodsInfo();
        return Result.success(goodsInfos);
    }

    @Override
    public Result queryGoodsInfoById(Integer id) {
        GoodsInfo goodsInfo = goodsInfoDao.queryGoodsInfoById(id);
        return goodsInfo != null ? Result.success(goodsInfo) :  Result.failure(400,"未找到对应的商品信息");    }
}
